package cn.bgs.wjx.WjxController;

import cn.bgs.CommunityManagement.pojo.Community;
import cn.bgs.UserManagement.pojo.File;
import cn.bgs.UserManagement.pojo.User;
import cn.bgs.utils.R;
import cn.bgs.wjx.WjxService.CommunityService;
import cn.bgs.wjx.pojo.*;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("gwb")
public class CommunityController {
    @Resource
    private CommunityService communityService;
    @Autowired
    private AliOss aliOss;
    //    生活缴费功能
    @GetMapping("/GwbCommunitywz")
    @ApiOperation(value = "小区所有位置查询")
    public R GwbCommunitywz(){
        List<Community> Community=communityService.Listcommunity();
        return R.ok().data("CommunityList1",Community);
    }

    @GetMapping("/GwbCommunityxx")
    @ApiOperation(value = "查询用户需要缴费的所有类型")
    public R GwbCommunityxx(Integer id){
        System.out.println(id);
        List<UserVo> GwbCommunityxx=communityService.ListUser(id);
        return R.ok().data("GwbCommunityxxList",GwbCommunityxx);
    }

    @GetMapping("/GwbCommunitydt")
    @ApiOperation(value = "查询用户如果有多个房子应缴物业费")
    public R GwbCommunitydt(Integer id,String type){
        List<UserVo> GwbCommunitydt=communityService.ListUserVo(id,type);
        System.out.println(GwbCommunitydt);
        return R.ok().data("GwbCommunityxxList",GwbCommunitydt);
    }

    @GetMapping("/Lifepayhistory")
    @ApiOperation(value = "查询用户缴费的历史记录")
    public R Lifepayhistory(Integer id,String type,String start,String end){
        List<TopUpVo> Lifepayhistory=communityService.Lifepayhistory(id,type,start,end);
        return R.ok().data("lifepayhistory",Lifepayhistory);
    }

    //维修上报功能------------------------------------------------------------------------------------
    @GetMapping("/Maintenance")
    @ApiOperation(value = "维修上报总览")
    public R Maintenance(Integer id){
        List<MaintenanceVo> Maintenance=communityService.Maintenance(id);
        return R.ok().data("Maintenance",Maintenance);
    }

    //   维修修改提交功能
    @PostMapping("/GwbUpdate")
    @ApiOperation(value = "维修修改提交功能")
    public R GwbUpdate(@RequestBody MaintenanceVo maintenanceVo){
        int i=communityService.GwbUpdate(maintenanceVo);
        if (i==1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    //   维修上报的撤销申请
    @GetMapping("/mainXqxg")
    @ApiOperation(value = "维修上报的撤销申请")
    public R mainXqxg(Integer maintenanceId){
        int i=communityService.mainXqxg(maintenanceId);
        if (i==1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    // 维修上报的申请添加功能
    @GetMapping("/AddmainList")
    @ApiOperation(value = "维修上报查询用户名下多少间房屋")
    public R AddmainList(Integer id){
        List<AddmainListVo> Maintenance1=communityService.AddmainList(id);
        return R.ok().data("Maintenance",Maintenance1);
    }

    //   维修申请添功能
    @PostMapping("/GwbAddTeance")
    @ApiOperation(value = "维修申请添功能")
    public R GwbAddTeance(@RequestBody MaintenanceVo maintenanceVo){
        System.out.println(maintenanceVo);
        if (maintenanceVo.getUrl()==null){
            return R.error();
        }
        int i=communityService.GwbAddTeance(maintenanceVo);
        if (i==1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    //社区活动功能------------------------------------------------------------------------------------

    // 查询社区活动表信息
    @GetMapping("/GwbActivity")
    @ApiOperation(value = "查询社区活动表信息")
    public R GwbActivity(Integer id){
        List<GwbActivityVo> Maintenance1=communityService.GwbActivity(id);
        return R.ok().data("CommunityList1",Maintenance1);
    }

    @GetMapping("/GwbActivity1")
    @ApiOperation(value = "查询社区活动表信息")
    public R GwbActivity1(Integer id){
        List<GwbActivityVo> Maintenance1=communityService.GwbActivity1(id);
        return R.ok().data("CommunityList1",Maintenance1);
    }

    //    投诉申请
    @PostMapping("/GwbAddshenqing")
    @ApiOperation(value = "投诉功能")
    public R GwbAddshenqing(@RequestBody GwbshenqingVo gwbshenqingVo){
        System.out.println(gwbshenqingVo);
        int i=communityService.GwbAddshenqing(gwbshenqingVo);
        if (i==1){
            return R.ok();
        }else {
            return R.error();
        }
    }

    //公告公示
    @GetMapping("/All")
    @ApiOperation(value = "公告公示")
    public R All(Integer id){
        List<AnnouncementVo> Maintenance1=communityService.All(id);
        return R.ok().data("CommunityList1",Maintenance1);
    }

    @GetMapping("/All1")
    @ApiOperation(value = "公告公示")
    public R All1(Integer id){
        List<AnnouncementVo> Maintenance1=communityService.All1(id);
        return R.ok().data("CommunityList1",Maintenance1);
    }


    //    注册功能
    @PostMapping("/Zhuce")
    @ApiOperation(value = "注册功能")
    public R Zhuce(@RequestBody User user){
        System.out.println(user);
        int i=communityService.Zhuce(user);
        if (i==1){
            return R.ok();
        }else {
            return R.error();
        }
    }
    @RequestMapping("/upload")
    public String upload(MultipartFile file){
        String file1=aliOss.upload(file);
        return file1;
    }

    //    修改余额钱数
    @PostMapping("/xgqs")
    @ApiOperation(value = "修改余额钱数")
    public R xgqs(@RequestBody UserVo uservo){
        System.out.println(uservo);
        int i=communityService.xgqs(uservo);
        if (i==1){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
